/*
 *  $Id: LandSpikes.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Earth.Spells {
    public class LandSpikes: SpellCard {
        public LandSpikes(): base("001_e_s_land_spikes") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Earth;
            Value = 100;
            AddManaCost(ElementType.Earth, 2);
        }

        public override void DoAction(TargetArgs args) {
            foreach (Creature cr in args.Player.Enemy.GetCreatures()) if (cr.MaxHealth > 4) {
                cr.DamageBy(NewDamage(args, 1));
                if (!cr.HasAffect<LandSpikesAffect>())
                    cr.AddAffect<LandSpikesAffect>();
            }
        }

        private class LandSpikesAffect: SpellAffect<LandSpikes> {
            private static readonly Languages.CardPhrase<LandSpikes> AfterAction = new Languages.CardPhrase<LandSpikes>("affect.wound.desc");
            private bool _wound;

            public LandSpikesAffect(): base(true) {
                DefaultDescription = true;
                _wound = false;
            }

            public override Languages.Phrase Description {
                get { return _wound ? AfterAction.Phrase : base.Description; }
            }

            public override void SetAffect() {
                base.SetAffect();
                if (!_wound) LocalSummary.OnOffenceReady += DoWound;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                if (!_wound) LocalSummary.OnOffenceReady -= DoWound;
            }

            private void DoWound(Creature creature) {
                if (_wound) return;
                ResetAffects();
                Add(new Affects.Wound(1));
                _wound = true;
                UpdateDescription();
                SetAffects();
            }
        }
    }
}
